package com.qding.park.manager.timer.schedule.job;

import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobKey;
import org.springframework.stereotype.Service;

import com.baidu.disconf.client.common.annotations.DisconfUpdateService;
import com.baidu.disconf.client.common.update.IDisconfUpdate;
import com.qding.park.common.core.constant.CacheKeyThree;
import com.qding.park.common.core.redis.JedisClient;
import com.qding.park.common.core.redis.SerializeUtils;
import com.qding.park.manager.pojo.queue.QueueMsg;
import com.qding.park.manager.pojo.queue.QueueTypeEnum;
import com.qding.park.manager.timer.ParkTimerApplication;
import com.qding.park.manager.timer.conf.TaskConfig;

/**
 * @ClassName ParkUseInfoSyncJob
 * @Description TODO(车场基础数据同步  :用户数据、车数据、车场计费规则)
 * @author Administrator
 * @Date 2016年9月5日 上午11:24:42
 * @version 1.0.0
 */
@Service
@DisconfUpdateService( classes={TaskConfig.class},itemKeys = { "task.ParkBaseDataSync.name" ,"task.ParkBaseDataSyncJob.taskJobClass","task.ParkBaseDataSyncJob.cronTime"})
public class ParkBaseDataSyncJob extends AbstractJob implements IDisconfUpdate{
	private static final Log _log = LogFactory.getLog(ParkBaseDataSyncJob.class);
	

	@Override
	public void execJob(JobExecutionContext context) {
		JobKey jobKey = context.getJobDetail().getKey();
		
		// 得到redis client
		JedisClient jedisClient = ParkTimerApplication.ctxUtil.getApplicationContext().getBean(JedisClient.class);
		
		//用户数据同步任务
		QueueMsg  UserInfoSynMsg=new QueueMsg();
		UserInfoSynMsg.setEventType(QueueTypeEnum.USERINFO_SYNC.getType());
		String userInfoMsgStr=SerializeUtils.serialize(UserInfoSynMsg);
		//用户数据同步　消息
		jedisClient.lpush(CacheKeyThree.QUEUE_ALL, userInfoMsgStr);
		
		
//		//车场数据同步
//		QueueMsg  parkInfoSynMsg=new QueueMsg();
//		parkInfoSynMsg.setEventType(QueueTypeEnum.PARKINFO_SYNC.getType());
//		String parkInfoSynStr=SerializeUtils.serialize(parkInfoSynMsg);
//		//车场数据数据同步　消息
//		jedisClient.lpush(CacheKeyThree.QUEUE_ALL, parkInfoSynStr);
		
		
//		//车场计费规则
//		QueueMsg  chargeRuleMsg=new QueueMsg();
//		chargeRuleMsg.setEventType(QueueTypeEnum.PARK_CHARGE_RULE_SYNC.getType());
//		String chargeRuleMsgSynStr=SerializeUtils.serialize(chargeRuleMsg);
//		//车场计费规则　消息
//		jedisClient.lpush(CacheKeyThree.QUEUE_ALL, chargeRuleMsgSynStr);
		
		
		try {
			Thread.sleep(1000*60*5);
		} catch (InterruptedException e) {
			_log.error(e, e);
		}
		_log.info("车场基础数据同步 : " + jobKey + " executing at " + new Date());
		
		

	}


	@Override
	public void reload() throws Exception {
		_log.info(TaskConfig.getTask_ParkBaseDataSync_name());
		String taskName=TaskConfig.getTask_ParkBaseDataSync_name();
		String cronTime=TaskConfig.getTask_ParkBaseDataSyncJob_cronTime();
		super.reloadTask(taskName,cronTime);
		
	}
}
